package com.example.armmvvm.ui.fallview

import android.view.View
import com.example.armmvvm.ui.view.AnchorSheetBehavior

/**
 * @author 创建人 ：yanghaozhang
 * @version 1.0
 * @package 包名 ：com.augurit.agmobile.agwater5.drainage.pipereview.view
 * @createTime 创建时间 ：2021/3/17
 * @modifyBy 修改人 ：
 * @modifyTime 修改时间 ：
 * @modifyMemo 修改备注：
 */
class AnchorFallViewSetting(
    var view: View,
    // 隐藏时回调,内部方法
    var hideCallBack: (() -> Unit)? = null,
    // 回调用于计算peekHeight和anchorHeight
    var calcHeight: ((View) -> Unit)? = null,
    // 是否可隐藏
    var hideable: Boolean = false,
    // 展示模式
    var mode: FallViewMode = FallViewMode.ONE_STATE,
    // 折叠时展示的高度
    var peekHeight: Int = 0,
    // 中间时展示的高度
    var anchorHeight: Int = 0,
    // 监听滑动,监听展示状态(折叠/展开/中间)的改变
    var behaviorListener: (AnchorFallViewStateCallBack.() -> Unit)? = null,
    // 展示时,如果容器中为空时,是否需要初始化状态为STATE_HIDDEN,从底部弹出
    var shouldHideBottomView: Boolean = true
) : IFallViewSetting

class AnchorFallViewStateCallBack : AnchorSheetBehavior.BottomSheetCallback() {
    private var onStateChangedCallback: (OnStateChangedFunction)? = null
    private var onSlideCallback: (OnSlideFunction)? = null
    fun onStateChanged(callback: OnStateChangedFunction) {
        onStateChangedCallback = callback
    }

    fun onSlide(callback: OnSlideFunction) {
        onSlideCallback = callback
    }

    override fun onStateChanged(bottomSheet: View, oldState: Int, newState: Int) {
        onStateChangedCallback?.invoke(bottomSheet, oldState, newState)
    }

    override fun onSlide(bottomSheet: View, slideOffset: Float) {
        onSlideCallback?.invoke(bottomSheet, slideOffset)
    }

    internal fun reset() {
        onStateChangedCallback = null
        onSlideCallback = null
    }
}
